package com.easytouch.vmhdl.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.easytouch.vmhdl.R;
import com.easytouch.vmhdl.activity.ManagerActivity;
import com.easytouch.vmhdl.interfaces.IManagerUpdateView;
import com.easytouch.vmhdl.presenter.ManagerUpdatePresenter;

/**
 * Created by gulin on 2018/1/25.
 */

public class UpdateFragment extends BaseMgrFragment implements View.OnClickListener, IManagerUpdateView{

    private ManagerUpdatePresenter mPresenter;

    private Button mBtUDisk;
    private Button mBtNet;
    private Button mBtBack;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_update, container, false);
        setTitle(R.string.mgr_update_title);

        mBtUDisk = view.findViewById(R.id.bt_udisk_update);
        mBtUDisk.setOnClickListener(this);
        mBtNet = view.findViewById(R.id.bt_net_update);
        mBtNet.setOnClickListener(this);
        mBtBack = view.findViewById(R.id.bt_back);
        mBtBack.setOnClickListener(this);

        mPresenter = new ManagerUpdatePresenter(this);

        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.bt_udisk_update:
                mBtUDisk.setEnabled(false);
                mBtNet.setEnabled(false);
                mPresenter.doUDiskUpdate();
                break;
            case R.id.bt_net_update:
                mPresenter.doNetUpdate();
                break;
            case R.id.bt_back:
                goToFragment(ManagerActivity.FRAGMENT_MENU, null);
                break;
        }
    }

    @Override
    public void showUDiskUpdateResultMessage(int result)
    {
        switch (result)
        {
            case IManagerUpdateView.OPT_SUCCESS:
                Toast.makeText(getActivity(), R.string.mgr_update_udisk_success, Toast.LENGTH_SHORT).show();
                break;
            case IManagerUpdateView.OPT_UDISK_NOT_EXIST:
                Toast.makeText(getActivity(), R.string.mgr_update_udisk_not_exist, Toast.LENGTH_SHORT).show();
                break;
            case IManagerUpdateView.OPT_NO_APK:
                Toast.makeText(getActivity(), R.string.mgr_update_udisk_no_apk, Toast.LENGTH_SHORT).show();
                break;
        }
        mBtUDisk.setEnabled(true);
        mBtNet.setEnabled(true);
    }
}
